package com.littleken.foodieApi.controller;

import com.littleken.foodieCommon.Response.ErrorCode;
import com.littleken.foodieCommon.Response.ServerResponse;
import com.littleken.foodieCommon.Utils.BeanCopierUtil;
import com.littleken.foodieCommon.constant.Constant;
import com.littleken.foodiePojo.domain.CarouselDO;
import com.littleken.foodiePojo.domain.CategoryDO;
import com.littleken.foodiePojo.vo.CarouselVO;
import com.littleken.foodiePojo.vo.CategoryVO;
import com.littleken.foodiePojo.vo.NewItemsVO;
import com.littleken.foodieService.CarouselService;
import com.littleken.foodieService.CategoryService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/*
 * Carousel Controller 轮播图展示
 * Create by littleken on 2020/11/24 10:04
 */
@RestController
@RequestMapping("/index")
public class IndexController {

    /**
     * 轮播图service
     */
    @Resource
    private CarouselService carouselService;

    /**
     * 商品分类service
     */
    @Resource
    private CategoryService categoryService;

    @GetMapping("/getAllCarousel")
    public ServerResponse<List<CarouselVO>> getAllCarousel(){
        List<CarouselDO> carouselDOList = carouselService.getAllCarousel(null);
        List<CarouselVO> carouselVOList = BeanCopierUtil.copyList(carouselDOList, CarouselVO.class);
        return ServerResponse.success(carouselVOList);
    }

    /**
     * 获取所有根类型分类
     * @return
     */
    @GetMapping("/getAllRootLevelCat")
    public ServerResponse<List<CategoryDO>> getAllRootLevelCat(){
        List<CategoryDO> allRootLevelCatList = categoryService.getAllRootLevelCat();
        return ServerResponse.success(allRootLevelCatList);
    }

    @GetMapping("/getAllSubCatList/{rootCatId}")
    public ServerResponse<List<CategoryVO>> getAllSubCatList(@PathVariable Integer rootCatId){
        List<CategoryVO> allSubCatList = categoryService.getAllSubCatList(rootCatId);
        return ServerResponse.success(allSubCatList);
    }

    @GetMapping("/getSixNewItemsLazy/{rootCatId}")
    public ServerResponse getSixNewItemsLazy(@PathVariable Integer rootCatId){
        List<NewItemsVO> sixNewItemsLazy = categoryService.getSixNewItemsLazy(rootCatId);
        return ServerResponse.success(sixNewItemsLazy);
    }

}
